﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SH.Common.CommonClass;
using SH.Common.CommonReturn;
using SH.Multitenant.API.Filters;
using SH.Multitenant.Application.IServices.IStore;

namespace SH.Multitenant.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [AllowAnonymous]
    public class StoreController : ControllerBase
    {
        private readonly IStoreServices _storeServices;

        public StoreController(IStoreServices storeServices)
        {
            _storeServices = storeServices;
        }
        /// <summary>
        /// 获取门店列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetStoreListAsync()
        {
            ApiResult<List<Store>> apiResult = new ApiResult<List<Store>>();
            var result = await _storeServices.GetStoreListAsync();
            apiResult.Success(result);
            return Ok(apiResult);
        }
        /// <summary>
        /// 获取租户下的所有的门店列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[Route("")]
        public async Task<IActionResult> GetStoreListByTenantIdUseForEmpAddAsync()
        {
            ApiResult<List<Store>> apiResult = new ApiResult<List<Store>>();
            var result = await _storeServices.GetStoreListByTenantIdAsync();
            apiResult.Success(result);
            return Ok(apiResult);
        }
        /// <summary>
        /// 分页获取租户下的门店列表
        /// </summary>
        /// <param name="address"></param>
        /// <param name="pageSIze"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetStoreListByTenantIdAsync(string? address, bool? storeStatus, string? storeName, int pageSize, int pageIndex)
        {
            var result = await _storeServices.GetStoreListByTenantIdAsync(address, storeStatus, storeName, pageSize, pageIndex);
            return Ok(result);
        }
        /// <summary>
        /// 店铺添加
        /// </summary>
        /// <param name="store"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        //[LogActionFilter("Store", "店铺添加")]
        public async Task<IActionResult> StoreAddAsync(Store store)
        {
            var result = await _storeServices.InsertAsync(store);
            ApiResult<int> apiResult = new ApiResult<int>();
            apiResult.Success(result);
            return Ok(apiResult);
        }
    }
}
